import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/login/index.vue'
import UserProfile from "@/components/user/UserProfile.vue";
import ActivityManagement from '@/components/content/ActivityManagement'
import NoticeManagement from '@/components/content/NoticeManagement'
import CaseManagement from '@/components/content/CaseManagement'
import ActivityIndex from "@/components/ActivityIndex";
import NoticeIndex from "@/components/NoticeIndex";
import Role from "@/components/user/Role.vue";
import Create from "@/components/vote/Create.vue";
import ListActivity from "@/components/vote/ListActivity.vue";
import VoteItem from "@/components/vote/VoteItem.vue";
import VoteEdit from "@/components/vote/VoteEdit.vue";
import Home from "@/components/Home";
import VoteResult from "@/components/vote/VoteResult.vue";
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace

// 重写 push 方法，避免冗余导航报错
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 重写 replace 方法
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err)
}

const routes = [
    {
      path: '/',
      name: 'Home',
      component: Home,
      redirect: '/home'
    },
    {
      path: '/home',
      name:'home',
      component: Home
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
  {
    path: '/admin',
    component: () => import('@/components/AdminIndex.vue'),
    children: [
      { path: '', redirect: '' },
      {
        path: 'user/profile',
        name: 'AdminUser',
        component: UserProfile
      },
      {
        path: 'account/info',
        name: 'UserInfo',
        component: () => import('@/components/account/UserInfo.vue')
      },
      {
        path: 'user/role',
        name: 'AdminRole',
        component: Role
      },
        {
            path: 'content/activity',
            name: 'ActivityManagement',
            component: ActivityManagement
        },
        {
            path: 'content/notice',
            name: 'NoticeManagement',
            component: NoticeManagement
        },
        {
            path: 'content/add/notice',
            name: 'CaseManagement',
            component: CaseManagement
        },
        {
            path: '/notice/detail/:id',
            name: 'noticeDetail',
            component: NoticeIndex
        },
        {
            path:'/activityIndex/:id',
            name:'ActivityIndex',
            component:ActivityIndex
        },

        {
            path: 'vote/add/index',
            name: 'Create',
            component: Create

        },
        {
            path: 'vote/add/item',
            name: 'VoteItem',
            component: VoteItem

        },
        {
            path: 'vote/add/setting',
            name: 'VoteEdit',
            component: VoteEdit
        },
        {
            path: 'vote/list',
            name: 'ListActivity',
            component: ListActivity
        },
        {
            path: 'vote/list/result',
            name: 'VoteResult',
            component: VoteResult
        }


    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


export default router
